﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using iTFF.WPF.Model.Toaster;
using System.IO;
using System.Windows.Media;

namespace iTFF.WPF.ViewModel
{
    class ToasterTrackViewModel : WorkspaceViewModel
    {

        #region Fields

        ToasterTrack _track;
        ToasterSkinViewModel _toasterSkin;

        #endregion

        #region Constructor

        public ToasterTrackViewModel(ToasterTrack track)
        {
            _track = track;
        }

        #endregion

        #region Base Properties

        public string Title
        {
            get { return _track.Title; }
            set
            {
                if (_track.Title != value)
                {
                    _track.Title = value;
                    OnPropertyChanged("Title");
                }
            }
        }

        public string Artist
        {
            get { return _track.Artist; }
            set
            {
                if (_track.Artist != value)
                {
                    _track.Artist = value;
                    OnPropertyChanged("Artist");
                }
            }
        }

        public string Album
        {
            get { return _track.Album; }
            set
            {
                if (_track.Album != value)
                {
                    _track.Album = value;
                    OnPropertyChanged("Album");
                }
            }
        }

        public string ImageFilePath
        {
            get { return _track.ImageFilePath; }
            set
            {
                if (_track.ImageFilePath != value)
                {
                    _track.ImageFilePath = value;
                    OnPropertyChanged("ImageSource");
                    OnPropertyChanged("ImageFilePath");
                }
            }
        }

        public int Stars
        {
            get { return _track.Stars; }
            set
            {
                if (_track.Stars != value)
                {
                    _track.Stars = value;
                    OnPropertyChanged("Stars");
                }
            }
        }

        public Stream ImageStream
        {
            get { return _track.ImageStream; }
            set
            {
                if (_track.ImageStream != value)
                {
                    _track.ImageStream = value;
                    OnPropertyChanged("ImageSource");
                    OnPropertyChanged("ImageStream");
                }
            }
        }

        public ToasterSkinViewModel ToasterSkin
        {
            get { return _toasterSkin; }
            set
            {
                if (_toasterSkin != value)
                {
                    _toasterSkin = value;
                    OnPropertyChanged("ToasterSkin");
                }
            }
        }

        #endregion

        #region Presentation properties

        /// <summary>
        /// Represents the image source : a file path or an ImageSource
        /// </summary>
        public object ImageSource
        {
            get
            {
                if (!string.IsNullOrEmpty(ImageFilePath))
                    return ImageFilePath;
                else if (ImageStream != null)
                    return ImageStream;
                else
                    return null;
            }
        }

        #endregion
    }
}
